<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>缺陷管理>>缺陷类型确认</title>
    <link rel="stylesheet" href="../layui/layui.all.js"  media="all">
    <script src="../js/jquery-3.4.1.js"></script>
</head>
<body >
<!--确认缺陷级别-->
<!--加面板-->
<div style="padding:10px;background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">缺陷管理>>缺陷类型确认</div>
                <div class="layui-card-body">
                    <!--数据表格-->
                    <table class="layui-hide" id="defect_table" lay-filter="defect_table"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<!--选中区域-->
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="zhiding">制定消缺任务</button>
    </div>
</script>

<!--表格中操作-->
<script type="text/html" id="operation">
    <a class="layui-btn layui-btn-xs" lay-event="look">查看</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="fenpei">分配任务</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="update">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancle">删除</a>
</script>

<script type="text/javascript">
    $(function () {
        var defect = sessionStorage.getItem("defect");
        if(defect != null){
            defect = JSON.parse(defect);
            $("#emp_name").text(defect.emp_name);
        }else{
//            window.location.href = "/login.html";
        }
    });
</script>

<script>

    layui.use(['table','layer'], function() {

        var table = layui.table
            ,layer=layui.layer;
        table.render({
            elem: '#defect_table'
            , url: '/querySolveTask.do'
            , toolbar: '#toolbarDemo'
            ,id:'test_defect_table'
            ,title:'缺陷等级'
            , totalRow: false
            , cols: [[
                {field: 'sovle_task', title: '任务编号', fixed: 'left',align:'center'}
                , {field: 'solve_name', title: '任务名称', align:'center'}
                , {field: 'work_order_des', title: '工作单据',align:'center'}
                , {field: 'user_name', title: '下发人',align:'center'}
                , {field: 'lssue_time', title: '下发时间',align:'center',templet : "<div>{{layui.util.toDateString(d.find_time, 'yyyy-MM-dd')}}</div>"}
                , {field: 'state_name', title: '任务状态',templet:'zhuangtai',align:'center'}
                , {field: 'sovlesuc_time', title: '任务完成时间',align:'center',templet : "<div>{{layui.util.toDateString(d.find_time, 'yyyy-MM-dd')}}</div>"}
                , {field: 'yesno_name', title: '任务是否取消',align:'center'}
                , {field: 'sovle_account', title: '消缺员',align:'center',}
                , {field: 'sovle_dec', title: '消缺描述',align:'center',}
                , {fixed: 'right', title: '操作',width:250, toolbar: '#operation',align:'center'}
            ]]
            , page: {
                limits: [5, 10, 15, 20]
            },

        });
        //头工具栏事件
        table.on('toolbar(defect_table)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            if(obj.event === 'zhiding') {
                var index = layer.open({
                    type: 2,
                    title: ['制定消缺任务 ', 'font-size:13px;background-color: #269ce9;color:white;text-algin:center'],
                    shade: [0.7, 'rgba(37,31,36,0.79)'],
                    area: ['70%', '80%'],
                    content: '/pages/zhidingSolve.html'
                    , end: function () {
                        //执行重载
                        table.reload('defect_table', {
                            where: {
                                key: {
                                    time: new Date()
                                }
                            }
                        }, 'data');
                    }
                });
            }
        });
        table.on('tool(defect_table)', function(obj) {
            var data1=obj.data;
            var data=table.cache['test_defect_table'];
          /*  sessionStorage.setItem('test',JSON.stringify(data));*/
            if (obj.event === 'look') {
                console.log(data1);
                var index=layer.open({
                    type: 2,
                    title: ['查看消缺任务 ','font-size:13px;background-color: #269ce9;color:white;text-algin:center'],
                    shade: [0.7, 'rgba(37,31,36,0.79)'],
                    area: ['30%', '80%'],
                    content:'/pages/solveSee.html',
                    success:function(layero,index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        body.find("#sovle_task").val(data1.sovle_task);
                        body.find("#solve_name").val(data1.solve_name);
                        body.find("#work_order_des").val(data1.work_order_des);
                        body.find("#user_name").val(data1.user_name);
                        body.find("#lssue_time").val(data1.lssue_time);
                        body.find("#sovlesuc_time").val(data1.sovlesuc_time);
                        body.find("#state_name").val(data1.state_name);
                        body.find("#sovle_account").val(data1.sovle_account);
                        body.find("#sovle_dec").val(data1.sovle_dec);
                    },
                    end:function () {
                        //执行重载
                        table.reload('test_defect_table');
                    }
                });
            }else if(obj.event==='fenpei'){
                var index=layer.open({
                    type: 2,
                    title: ['分配消缺任务 ','font-size:13px;background-color: #269ce9;color:white;text-algin:center'],
                    shade: [0.7, 'rgba(37,31,36,0.79)'],
                    area: ['30%', '50%'],
                    content:'/pages/feipeiTask.html',
                    success:function(layero,index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        body.find("#sovle_task").val(data1.sovle_task);
                        body.find("#solve_name").val(data1.solve_name);
                        body.find("#work_order_des").val(data1.work_order_des);
                        body.find("#user_name").val(data1.user_name);
                        body.find("#lssue_time").val(data1.lssue_time);
                        body.find("#sovlesuc_time").val(data1.sovlesuc_time);
                        body.find("#state_name").val(data1.state_name);
                        body.find("#sovle_account").val(data1.sovle_account);
                        body.find("#sovle_dec").val(data1.sovle_dec);
                    },
                    end:function () {
                        //执行重载
                        table.reload('test_defect_table');
                    }
                });
            }else if(obj.event==='update'){
                var index= layer.open({
                    type: 2,
                    title: ['修改消缺任务 ','font-size:13px;background-color: #269ce9;color:white;text-algin:center'],
                    shade: [0.7, 'rgba(37,31,36,0.79)'],
                    area: ['72%', '100%'],
                    content:'/pages/update_solveTask.html',
                    success:function(layero,index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        body.find("#sovle_task").val(data1.sovle_task);
                        body.find("#solve_name").val(data1.solve_name);
                        body.find("#work_order_des").val(data1.work_order_des);
                        body.find("#user_name").val(data1.user_name);
                        body.find("#lssue_time").val(data1.lssue_time);
                        body.find("#sovlesuc_time").val(data1.sovlesuc_time);
                        body.find("#state_name").val(data1.state_name);
                        body.find("#sovle_account").val(data1.sovle_account);
                        body.find("#sovle_dec").val(data1.sovle_dec);
                    },
                    end:function () {
                        //执行重载
                        table.reload('test_defect_table');
                    }
                });
            }else if(obj.event==='cancle'){
                layer.confirm('是否取消任务?', function(index){
                    var sovle_task = data1.sovle_task;
                    var yesno_name=data1.yesno_name;
                    var state=1;
                    if ( yesno_name=='是'){
                       state=2;
                        console.log(state);
                    }else if( yesno_name=='否'){
                       state=1;
                        console.log(state);
                    }
                    $.ajax({
                        url: "/cancleYesNo",
                        type: "post",
                        data: {sovle_task:sovle_task,state:state},
                        dataType: "json",
                        success:function(result){
                            if(result.code == 200){// 成功
                                obj.del();
                                //执行重载
                                table.reload('defect_table', {
                                    where: {
                                        key: {
                                            time: new Date()
                                        }
                                    }
                                }, 'data');
                                layer.close(index);
                            }
                            //出现异常等其他情况
                            if(result.code == 501){
                                alert(result.message);
                                layer.close(index);
                            }
                        }

                    }) ,
                        table.reload('defect_table', {
                        where: {
                            key: {
                                time: new Date()
                            }
                        }
                    }, 'data');
                    layer.close(index);
                });
            }
        });
    });
</script>
</body>
</html>
<!-- -->